package com.tuanzi.loan.business.service.statistics.impl;

import com.tuanzi.loan.business.repository.statistics.LoanHitLibraryResultRepository;
import com.tuanzi.loan.business.service.statistics.LoanHitLibraryResultService;
import com.tuanzi.loan.core.aspect.Debug;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Simon
 * @date 2019/06/20 13:55
 */
@Slf4j
@Debug
@Service
@Transactional
@Retryable(value = {RetryException.class})
public class LoanHitLibraryResultServiceImpl implements LoanHitLibraryResultService {

    @Autowired
    private LoanHitLibraryResultRepository loanHitLibraryResultRepository;

    @Override
    public void deleteNewUserByDay() {
        loanHitLibraryResultRepository.deleteNewUserByDay();
    }

    @Override
    public void deleteOldUserByWeeks() {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //一周前那天
        Date day=new Date(new Date().getTime()-1000*60*60*24*7);
        String date = format.format(day); //格式化前一天
        //起始时间
        String startDate = date.substring(0,10)+" 00:00:00";
        loanHitLibraryResultRepository.deleteOldUserByWeeks(startDate);
    }
}
